<?php

/**
 * Adding a GotStudentActivity
 * @package ModuleGestionUniversitaire
 * @version 1.0b
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// Format purposes
	$dateFrom = explode('/', $_POST['from']);
	$dateFrom = $dateFrom[2].'-'.$dateFrom[1].'-'.$dateFrom[0];
	$dateTo = explode('/', $_POST['to']);
	$dateTo = $dateTo[2].'-'.$dateTo[1].'-'.$dateTo[0];
	
	// Creating gotStudentActivity
	$gotstudentactivity = new GotStudentActivity();
	$gotstudentactivity->companyId = $_POST['company'];
	$gotstudentactivity->contactId = $_POST['contact'];
	$gotstudentactivity->from = $dateFrom;
	$gotstudentactivity->to = $dateTo;
	$gotstudentactivity->description = $_POST['content'];
	$gotstudentactivity->studentactivityId = $_POST['studentactivity'];
	
	if (!empty($_POST['remunamount'])) {
		$remuneration = new Remuneration();
		$remuneration->type = $_POST['remuntype'];
		$remuneration->amount = $_POST['remunamount'];
		
		$remuneration->SaveNew();
		$gotstudentactivity->SetRemuneration($remuneration);
	}
	
	// Inserting gotStudentActivity into database
	$gotstudentactivity->SaveNew();
	
	echo 'OK';

} catch (Exception $e) {
	echo $e->getMessage();
}
?>